package com.fulihui.usercore.biz.conv;

import com.fulihui.usercore.dal.dataobj.WechatUser;
import com.fulihui.usercore.dal.dataobj.WechatUserDO;
import com.fulihui.usercore.dto.WechatUserDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by Willard.Hu on 2016/5/21.
 */
public class WechatUserConv {

    @Deprecated
    public static WechatUserDO toDO(WechatUserDTO dto) {
        if (dto == null) {
            return null;
        }
        WechatUserDO wuDO = new WechatUserDO();
        BeanUtils.copyProperties(dto, wuDO);
        return wuDO;
    }

    @Deprecated
    public static WechatUserDTO toDTO(WechatUserDO weDO) {
        if (weDO == null) {
            return null;
        }
        WechatUserDTO dto = new WechatUserDTO();
        BeanUtils.copyProperties(weDO, dto);
        return dto;
    }

    @Deprecated
    public static List<WechatUserDTO> toList(List<WechatUserDO> doList) {
        if (CollectionUtils.isEmpty(doList)) {
            return Collections.emptyList();
        }
        return doList.stream().map(WechatUserConv::toDTO).collect(Collectors.toList());
    }

    public static WechatUser toObj(WechatUserDTO dto) {
        if (dto == null) {
            return null;
        }
        WechatUser obj = new WechatUser();
        BeanUtils.copyProperties(dto, obj);
        return obj;
    }

    public static WechatUserDTO toDTO(WechatUser obj) {
        if (obj == null) {
            return null;
        }
        WechatUserDTO dto = new WechatUserDTO();
        BeanUtils.copyProperties(obj, dto);
        return dto;
    }

    public static List<WechatUserDTO> toDTOList(List<WechatUser> list) {
        if (CollectionUtils.isEmpty(list)) {
            return Collections.emptyList();
        }
        return list.stream().map(WechatUserConv::toDTO).collect(Collectors.toList());
    }
}
